<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>盘点单</title>
<link rel="stylesheet" type="text/css"
	href="../extjs/resources/css/ext-all.css" />
<script type="text/javascript" src="../extjs/ext-all.js"></script>
<script type="text/javascript" src="../extjs/ext-lang-zh_CN.js"></script>

<script>
	Ext.onReady(function(){
	 	Ext.BLANK_IMAGE_URL = "extjs/resources/images/default/s.gif";
	    Ext.QuickTips.init();
		mainWindow.show();
		
});
/*{
    xtype: "button",
    id: "btn1",
    text: "小按钮",
    handler: function () {
        Ext.MessageBox.alert("提示", "通过handler配置项添加的事件");
    }
}*/
var fielmenu=new Ext.menu.Menu({
		items:[{text:'载入物料'},{text:'批号设定'}]
	});
	
var save=new Ext.menu.Menu({
	items:[{
		text:'主祥新增',handler: function () {
			alert("fdkl");
			saveInvtentory();
		}
    }]
});	
	var grids=Ext.create('Ext.grid.Panel',{
	    
		 listeners:{
					containerdblclick: function(grid, e, eOpts){ //单击事件
		    						grid.getStore().add({'name':'12', 'dizhi':'','bianma':'','lianxi':''});
	    						
	    					},
						itemcontextmenu:function(){
						
	    						e.preventDefault();
	    						new Ext.menu.Menu({
	    							items:[{
	    								xtype: 'textfield',
	    								text: 'Lost',
	    								pressed: false,
	    								handler:function(){
												alert();
											}
	    							},{
	    								xtype: '',
	    								text: '盘点仓库',
	    								pressed: false,
	    								handler: function(){}
	    							},{
	    								xtype: '',
	    								text: '閫夋嫨鏂规',
	    								pressed: false,
	    								menu:new Ext.menu.Menu({
	    									items:[{
	    										text:'棰勮鏂规',
	    										pressed: false
	    									}]
	    								}),
	    								handler: function(){}
	    							},{
	    								xtype: '',
	    								text: '瀵煎嚭鑷矱xcel',
	    								pressed: false,
	    								handler: function(){}
	    							},{
	    								xtype: '',
	    								text: '缃戞牸鎵撳嵃',
	    								pressed: false,
	    								handler: function(){}
	    							}]
	    						}
	    						
	    						).showAt(e.getXY());
					}
				},plugins: [
	        				Ext.create('Ext.grid.plugin.CellEditing', {
	            				clicksToEdit: 1
	        				})
	    				],
		columns: [
					 {header: '（栏号）',
		                    		xtype: 'rownumberer',
		                    		dataIndex: 'lh', 
		                    		width: 50,
									sortable: false
	        					},
						
	        		{ header: '物料编号',  dataIndex: 'prodID', width: 100,},
	       			 { header: '（物料名称）', dataIndex: 'dizhi',width: 120,editor: { xtype:'textfield',
					 	listeners:{
							focus:function(grid, e, eOpts){
									windows2.show();
									}
								
						}
					 } },
						 { header: '（单位）', dataIndex: 'util' },
						 { header: '（账面数量）', dataIndex: 'sumCur'},
						 { header: '盘点数量', dataIndex: 'sumCheck' },
						 { header: '（盈亏数量）', dataIndex: 'sumnum' },
						 { header: '单价', dataIndex: 'price' },
						 { header: '（盈亏金额）', dataIndex: 'sums' },
						 { header: '（批号）', dataIndex: 'ph' }
	   					 ],
	   			/* height: 130,
				 width:950,
				 autoScroll:false,*/
				 
	})

	var ppa = Ext.create('Ext.panel.Panel', {
	    bodyPadding: 6,  // 避免Panel中的子元素紧邻边框
	    width: 1985,
		height:170,
	    items:[grids],
		bbar:[{xtype:"label",text:'总计:',width:70},
		{xtype:"textfield",disabled:true,width:70,margin:'0 0 0 160',value:'0.00'},
		{xtype:"textfield",disabled:true,width:70,margin:'0 0 0 15',value:'0.00'},
		{xtype:"textfield",disabled:true,width:70,margin:'0 0 0 15',value:'0.00'},
		{xtype:"textfield",disabled:true,width:70,margin:'0 0 0 60',value:'0.00'}]
	});

	
	var  tbl=Ext.create('Ext.TabPanel',{
		width:"100%",
		height:230,
		autoScroll:true,
		bodyPadding: 5,
		items:[{title:'内容',autoScroll:true,items:[ppa]},{title:'备注',xtype:'textarea',name:'Remark',fieldLabel: '备注',labelWidth: 30,}]
	});

	
	var formsg=Ext.create('Ext.form.Panel', {
	    bodyPadding: 5,
		height:'100%',
		layout:"column",
		baseCls:'x-plain',
		items:[{
			id:'salesID',
			xtype: 'textfield',
	        name: 'SalesMan',
			bodyPadding: 5,
	        fieldLabel: '盘点人员',
			width:250,
	        labelWidth: 80,
	        style:'margin-left:30px',
	        anchor: '100%',
				},{
			id:'marker',
			xtype: 'textfield',
	        name: 'Marker',
	        fieldLabel: '制单人员',
			style:'margin-left:70px',
			width:250,
	        labelWidth: 80,
	        anchor: '100%',
				},{
			id:'departID',
			xtype: 'textfield',
	        name: 'ProdDepart',
	        fieldLabel: '所属部门',
			width:250,
	        labelWidth: 80,
	        style:'margin-left:30px',
	        anchor: '100%',
				},{
			id:'permitter',		
			xtype: 'textfield',
	        name: 'Permitter',
	        fieldLabel: '复核人员',
			style:'margin-left:70px',
			width:250,
	        labelWidth: 80,
	        anchor: '100%',
				}],
		});


var formpalcd=Ext.create('Ext.form.Panel', { //表单
    bodyPadding: 5,
    width:'100%',
    // 将会通过 AJAX 请求提交到此URL
   // url: 'save-form.php',
    // 表单域 Fields 将被竖直排列, 占满整个宽度
    layout: 'column',
    defaults: {
        anchor: '100%'
    },

    // The fields
    defaultType: 'textfield',
    items: [{
    	    id:'wareID',
			xtype: 'textfield',
       		name: 'supplierId',
			fieldLabel: '盘点仓库',
			margin:'5 45',
       		labelWidth: 70           
			},{
			id:'adjustDate',
			style:'margin-left:9px',
			xtype : 'datefield',
	        name: 'accountBelong',
	        fieldLabel: '单据日期',
	        format:'Y-m-d',
	        margin:'5 45',
	        labelWidth: 70,	        
	        anchor: '100%',
			},{
			id:'incSubjectName',
			xtype: 'textfield',
	        name:'supplierFullName',
	        fieldLabel: '增值科目',
	        margin:'5 45',
	        labelWidth: 70,
	        value:new Date(),
	        anchor: '100%',
			},{
			id:'billno',
		    style:'margin-left:9px',
			xtype: 'textfield',
	        name: 'genre',
	        fieldLabel: '单据号码',
	        labelWidth: 70,
	        margin:'5 45',
			//vtype:'url',//只能输入网址
	        anchor: '100%',
			},{
			id:'decSubjectName',
			xtype: 'textfield',
	        name: 'supplierSimName',
	        fieldLabel: '减值科目',
	        labelWidth: 70,
	        margin:'5 45',
			regex:/^[\u4E00-\u9FA5]+$/,//自定义正则表达式,(只能输入汉字);
			regexText:'叫你输入汉字啊,SB吗？',//提示
	        anchor: '100%',
			},{
			id:'voucherNO',
			style:'margin-left:9px',
			xtype: 'textfield', //多行文本域
	        name: 'area',
	        fieldLabel: '凭证编号',
	        labelWidth: 70,
	        margin:'5 45',
	        anchor: '100%',
			},tbl,formsg]
     
});


var mainWindow = new Ext.Window({
		
		width:660,
		height:480,
		title:"盘点单",
		closable:true,
		resizable:false, //设置是否可以改变大小
		draggable:true, //设
		items:[formpalcd],
		listeners : {
			activate : function() {
				findAlls();
			}
		},
		bbar:[{xtype:"splitbutton",text:'功能',width:90,menu:fielmenu},{xtype:"splitbutton",text:'保存',width:90,menu:save}],
	});

function fromaction(){
	alert(Ext.encode(formpalcd.getForm().getValues()));// 序列化表单
}
//查询主表最大的单号数据 
function findAlls() {
	//var song=Ext.encode(forms.getForm().getValues());
	Ext.Ajax.request({
		//被用来向服务器发起请求默认的url  
		url : "/lf/findAll",
		//请求时发送后台的参数,既可以是Json对象，也可以直接使用“name = value”形式的字符串  
		params :{currentPage:1},
		//请求时使用的默认的http方法  
		method : "post",
		//请求成功时回调函数  
		success : function(data) {
		 var pp=Ext.JSON.decode(data.responseText)
		   // alert(JSON.stringify(pp));
		  //alert(pp);
			Ext.getCmp('wareID').setValue(pp.data.wareID);
			Ext.getCmp('adjustDate').setValue(pp.data.adjustDate );
			Ext.getCmp('incSubjectName').setValue(pp.data.incSubjectName);	
			Ext.getCmp('billno').setValue(pp.data.billno);
			Ext.getCmp('decSubjectName').setValue(pp.data.decSubjectName);
			Ext.getCmp('voucherNO').setValue(pp.data.voucherNO);
			Ext.getCmp('salesID').setValue(pp.data.salesID);
			Ext.getCmp('marker').setValue(pp.data.marker);
			Ext.getCmp('departID').setValue(pp.data.departID);
			Ext.getCmp('permitter').setValue(pp.data.permitter);
			//Ext.ux.Toast.msg("信息提示", "成功删除所选记录！");
			grids.getStore().add(pp.data.detail);
	        /* newsStore.load({  
	            url: pp,  
	            params: {  
	                start: 0,  
	                limit: 20  
	  
	            }  			  
	        });   */			     			
		},
		//请求失败时回调函数  
		failure : function() {
			//Ext.ux.Toast.msg("信息提示", "信息删除出错，请联系管理员!");
		}
	});
}

//保存 
function saveInvtentory(){
	//获取明细表数据 
	//var details=grids.getStore();
	var details=Ext.pluck(grids.getStore().data.items,"data");
	alert(JSON.stringify(details));
	//获取主表数据 
	var inv={
			wareID:Ext.getCmp('wareID').getValue(),
	        adjustDate:Ext.getCmp('adjustDate').getValue(),
	        incSubjectName:Ext.getCmp('incSubjectName').getValue(),	
	        billno:Ext.getCmp('billno').getValue(),
	        decSubjectName:Ext.getCmp('decSubjectName').getValue(),
	        voucherNO:Ext.getCmp('voucherNO').getValue(),
	        salesID:Ext.getCmp('salesID').getValue(),
	        marker:Ext.getCmp('marker').getValue(),
	        departID:Ext.getCmp('departID').getValue(),
	        permitter:Ext.getCmp('permitter').getValue(),
	        detail:details
	}
	 alert(JSON.stringify(inv)); 
	Ext.Ajax.request({
		//被用来向服务器发起请求默认的url  
		url : "/lf/insertInventory",
		headers: {'Content-Type':'application/json'},
		//请求时发送后台的参数,既可以是Json对象，也可以直接使用“name = value”形式的字符串  
		params :JSON.stringify(inv),
		//请求时使用的默认的http方法  
		method : "post",		 
		//请求成功时回调函数  
		success : function(data) {
		   alert("保存成功");		
		},
		//请求失败时回调函数  
		failure : function() {
			alert("信息提示", "信息删除出错，请联系管理员!");
		}
	});
	
}
</script>
</head>

<body>
</body>
</html>
